; (function (win, doc) {


    // 楼层数组中对象接口类型
    interface FloorData {
        Name: string,
        FloorID: string,
        Order: number,
        Area: [any]
    }


    // 楼层切换模块外层样式对象接口类型
    interface FloorToggleCss {
        left: string,
        width: string,
        height: string,
    }

    // 楼层切换模块里层按钮样式对象接口类型
    interface FloorToggleLiCss {
        width: string;
        height: string;
        color: string;
        fontSize: string;
        backgroundColor: string;
        marginBottom: string;
        borderRadius: string;
    }

    // 默认参数配置数据类型接口
    interface DefaultSet {
        container: string,
        containerCss: FloorToggleCss,
        floorLiCss: FloorToggleLiCss,
    }

    // 传入配置参数接口类型
    interface DefaultOption {
        container: string,
        floorData: [FloorData]
        containerCss: FloorToggleCss,
        floorLiCss: FloorToggleLiCss,
        map: any
    }

    // 默认参数配置
    const defaultSettings: DefaultSet = {
        container: "floorToggle",
        containerCss: {
            left: "1rem",
            width: "4rem",
            height: "15rem"
        },
        floorLiCss: {
            width: "100%",
            height: "2.5rem",
            color: "#595959",
            fontSize: "0.27rem",
            backgroundColor: "#f7f7f3",
            marginBottom: ".5rem",
            borderRadius: "2px",
        },
    };


    class FloorToggle {
        area: [FloorData];
        container: any;
        containerCss: FloorToggleCss;
        floorLiCss: FloorToggleLiCss
        map: any;

        constructor(options: DefaultOption) {

            let self: any = this;

            if (!options) {
                throw new Error("请传入配置参数");
            }

            self = Object.assign(self, defaultSettings, options);

            self.container = doc.getElementById(self.container);

            self.initFloor()
        }

        private initFloor() {

            let self = this,
                floorToggleLiHtml: string = '';

            self.area.forEach(element => {
                floorToggleLiHtml = floorToggleLiHtml + `
                    <li class="floorToggleUl_List" id="floorToggleUl_List">
                       <i class="floorToggleMinUl_i"></i>
                       <div class="floorToggleLi" name="btn" data=${element.FloorID} value="${element.Name}">${element.Name}</div>
                    </li>
                    `
            })

            self.container.innerHTML = floorToggleLiHtml;

            // 设置最外层盒子的css属性
            self.container.style.cssText = `list-style-type: none;
            position: absolute;
            left: ${self.containerCss.left};
            top: 50%;
            transform: translateY(-50%);
            width: ${self.containerCss.width};
            height: ${self.containerCss.height};
            overflow: auto;`;

            // 设置每个li的css属性
            const toggleLi: any = doc.getElementsByClassName('floorToggleUl_List')

            for (let i: number = 0; i < toggleLi.length; i++) {
                toggleLi[i].style.cssText = `
                width: ${self.floorLiCss.width};
                height: ${self.floorLiCss.height};
                text-align: center;
                font-size: ${self.floorLiCss.fontSize};
                line-height: ${self.floorLiCss.height};
                color: ${self.floorLiCss.color};
                background-color: ${self.floorLiCss.backgroundColor};
                margin-bottom: ${self.floorLiCss.marginBottom};
                border-radius: ${self.floorLiCss.borderRadius};
                `

                if (toggleLi[i].children[1].innerHTML == '1F' || toggleLi[i].children[1].innerHTML == '1f' || toggleLi[i].children[1].innerHTML == 'f1' || toggleLi[i].children[1].innerHTML == 'F1' || toggleLi[i].children[1].innerHTML == '1L' || toggleLi[i].children[1].innerHTML == '1l' || toggleLi[i].children[1].innerHTML == 'L1' || toggleLi[i].children[1].innerHTML == 'l1') {
                    toggleLi[i].children[1].style.cssText = `border: 1px solid #ac3838;border-radius: 3px;color: #ac3838`;
                }



                toggleLi[i].addEventListener('click', () => {


                    if (self.map) {

                        self.map.showFloors([self.area[i].FloorID], true);

                        for (let index = 0; index < toggleLi.length; index++) {
                            const element = toggleLi[index];
                            element.children[1].style.cssText = `border-radius: 3px;color: #595959`;
                        }
                        toggleLi[i].children[1].style.cssText = `border: 1px solid #ac3838;border-radius: 3px;color: #ac3838`;

                    } else {

                        console.log('你没有传入初始化地图对象');

                    }

                })
            }





        }

        public selectFloorColor(selectFloors: [string]) {
            let matchIndex: number = 0;

            if (!selectFloors) {
                throw new Error("请传入选中楼层参数");
            }

            const toggleLi: any = doc.getElementsByClassName('floorToggleUl_List')


            for (let index = 0; index < toggleLi.length; index++) {
                const element = toggleLi[index];
                element.children[1].style.cssText = `border-radius: 3px;color: #595959`;


                selectFloors.forEach((e) => {
                    if (e == element.children[1].getAttribute('data')) {
                        element.children[1].style.cssText = `border: 1px solid #ac3838;border-radius: 3px;color: #ac3838`;
                        matchIndex++
                    }
                })


            }

            if (matchIndex != selectFloors.length) {
                throw new Error("传入的楼层中有与地图初始化楼层不匹配项");
            }


        }



    }

    (<any>window).FloorToggle = FloorToggle;

})(window, document)






